import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    X = ["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000"]
    # X = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
    Y1 = [100.1, 200.2, 300.2, 387.52, 492.36, 597.9, 694.36, 713.32, 711.44, 721.9] #左侧坐标，在这条线上的点写上时延
    Y2 = [0.01, 0.01, 0.01, 0.018, 0.024, 0.032, 0.048, 0.058, 0.06, 0.078] #右侧坐标
    # Y3 = ["SR:100%", "SR:1", "SR:1", "SR:1", "SR:1", "SR:1", "SR:1", "SR:1", "SR:1", "SR:1"] #结点上的坐标
    # for i in range(1, len(Y1)):
    #     Y2.append((Y1[i] - Y1[i - 1]) / Y1[i - 1])
    fig, ax1 = plt.subplots()
    # plt.xticks(rotation=45)
    # ax1.set_title('READ Performance')
    ax1.plot(X, Y1, color="blue", label="Throughput", linewidth=1.0, linestyle='-', marker='o')
    # for循环
    # for num in range(0, 10):
    #     plt.annotate(Y3[num], (X[num], Y1[num]+40), ha='center')

    # ax1.annotate(text='3', xy=("100", 200))

    ax1.set_xlabel("Send Rate (TPS)", fontsize=15)
    ax1.set_ylabel("Throughput (TPS)", fontsize=15) # fontsize=15
    plt.xticks(fontsize=13, rotation=30)
    plt.yticks(np.linspace(100, 1000, 10, endpoint=True), fontsize=13)

    # 在上面这条线上，增加时延

    # 不显示呢？？？https://www.modb.pro/db/412416

    ax2 = ax1.twinx()
    ax2.plot(X, Y2, color="red", label="Avg Latency",linewidth=1.5,linestyle=':',marker='o')
    ax2.set_ylabel("Avg Latency (s)", fontsize=15)
    plt.yticks(np.linspace(0.01, 0.1, 10, endpoint=True), fontsize=13)

    fig.legend(loc="upper left", bbox_to_anchor=(0, 0, 0, 1), bbox_transform=ax1.transAxes, fontsize=15)

    plt.savefig('/Users/minghuili/Downloads/9-a.eps', dpi=300, bbox_inches='tight')
    plt.show()